package com.atguigu.c_designed.m1createModel.c4builder;

// client
public class Client {
    public static void main(String[] args) {
        Director director = new Director();
        Bike bike = director.construct(new Ofobike());
        System.out.println(bike);
    }
}

// Director 指挥者类（Director）：调用具体建造者来创建复杂对象的各个部分，在指导者中不涉及具体产品的信息，只负责保证对象各部分完整创建或按某种顺序创建。
class Director{

    public Bike construct(Builder builder){
        builder.buildFrame();
        builder.buildSeat();
        return builder.build();
    }
}
// product 产品类（Product）：要创建的复杂对象。
class Bike{
    private String frame;
    private String seat;

    public String getFrame() {
        return frame;
    }

    public void setFrame(String frame) {
        this.frame = frame;
    }

    public String getSeat() {
        return seat;
    }

    public void setSeat(String seat) {
        this.seat = seat;
    }

    @Override
    public String toString() {
        return "Bike{" +
                "frame='" + frame + '\'' +
                ", seat='" + seat + '\'' +
                '}';
    }
}

// builder 抽象建造者类（Builder）：这个接口规定要实现复杂对象的那些部分的创建
abstract class Builder{
    protected Bike bike = new Bike();

    abstract void buildFrame();
    abstract void buildSeat();
    abstract Bike build();
}

// ConcreteBuilder 具体建造者类（ConcreteBuilder）：
// 实现 Builder 接口，完成复杂产品的各个部件的具体创建方法。在构造过程完成后，提供产品的实例。
class Mobike extends Builder{

    @Override
    void buildFrame() {
        bike.setFrame("碳纤维车身");
    }

    @Override
    void buildSeat() {
        bike.setSeat("真皮座椅");
    }

    @Override
    Bike build() {
        return bike;
    }
}

// ConcreteBuilder 具体建造者类（ConcreteBuilder）：
class Ofobike extends Builder{

    @Override
    void buildFrame() {
        bike.setFrame("垃圾车身");
    }

    @Override
    void buildSeat() {
        bike.setSeat("垃圾座椅");
    }

    @Override
    Bike build() {
        return bike;
    }
}

